//
//  ZSNewsDataTableViewCell.m
//  fangwangyi
//
//  Created by 臧松 on 16/4/27.
//  Copyright © 2016年 zangsong. All rights reserved.
//

#import "ZSNewsDataTableViewCell.h"
#import "UIImageView+WebCache.h"
#define kWIDTH [UIScreen mainScreen].bounds.size.width
#define kHEIGHT [UIScreen mainScreen].bounds.size.height
@interface ZSNewsDataTableViewCell ()
@property (nonatomic,strong) UIImageView * iconImage;
@property (nonatomic,strong) UILabel * titleLabel;
@property (nonatomic,strong) UILabel * digestLabel;
@property (nonatomic,strong) UILabel * replyLabel;

@end
@implementation ZSNewsDataTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle: style reuseIdentifier:reuseIdentifier]) {
        self.iconImage = [[UIImageView alloc]init];
        
        self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(136, 8, kWIDTH - 144, 30)];
        self.titleLabel.font = [UIFont systemFontOfSize:16];
        
        self.digestLabel = [[UILabel alloc]initWithFrame:CGRectMake(136, 46, kWIDTH - 144, 30)];
        self.digestLabel.font = [UIFont systemFontOfSize:14];
        self.digestLabel.numberOfLines = 0;
        
        self.replyLabel = [[UILabel alloc]init];
        self.replyLabel.font = [UIFont systemFontOfSize:11];
        self.replyLabel.backgroundColor = [UIColor redColor];
        self.replyLabel.layer.cornerRadius = 3;
        
        self.replyLabel.layer.masksToBounds = YES;
        
        [self.contentView addSubview:_iconImage];
        [self.contentView addSubview:_replyLabel];
        [self.contentView addSubview:_titleLabel];
        [self.contentView addSubview:_digestLabel];
        
    }
    return  self;
}
-(void)setNewsData:(ZSNewsData *)newsData{
    _newsData = newsData;
    
    NSURL * url = [NSURL URLWithString:newsData.imgsrc];
    [self.iconImage sd_setImageWithURL:url];
    self.titleLabel.text = newsData.title;
    
    self.digestLabel.text = newsData.digest;
    self.replyLabel.text = [NSString stringWithFormat:@"跟帖%@",newsData.replyCount];
    [self.replyLabel sizeToFit];
}
-(void)layoutSubviews{
    [super layoutSubviews];
    self.iconImage.frame = CGRectMake(8, 8, 120, 84);
    self.titleLabel.frame = CGRectMake(self.iconImage.frame.size.width + 16, 8, kWIDTH - 24-120, self.titleLabel.frame.size.height);
    self.digestLabel.frame = CGRectMake(self.iconImage.frame.size.width +16, self.titleLabel.frame.size.height + 16, kWIDTH - 24 - 120, self.digestLabel.bounds.size.height);
    
    self.replyLabel.frame = CGRectMake(kWIDTH - self.replyLabel.bounds.size.width - 8, 100-self.replyLabel.bounds.size.height -8, self.replyLabel.bounds.size.width, self.replyLabel.bounds.size.height);
    
}
@end
